package com.example.demo.util;

import com.example.demo.entity.enums.CodeEnum;
import com.example.demo.vo.R;

/**
 * @program: demo
 * @description: 返回结果工具类
 * @author: 陈程猿
 * @create: 2024-12-11 09:15
 **/

public class RUtil {
    // 成功
    public static R success(Object obj,Long count){
        R res=new R();
        res.setCode(CodeEnum.SUCCESS.getCode());
        res.setData(obj);
        res.setCount(count);
        res.setMsg(CodeEnum.SUCCESS.getMsg());
        return res;
    }
    public static R success(Object obj){
        return success(obj,null);
    }

    // 无参
    public static R success(){
       return success(null);
    }

    public static R error(Integer  code,String msg){
        R res=new R();
        res.setCode(code);
        res.setMsg(msg);
        return res;
    }
    // 枚举类参数
    public static R error(CodeEnum codeEnum){
        R res=new R();
        res.setCode(codeEnum.getCode());
        res.setMsg(codeEnum.getMsg());
        return res;
    }
}
